﻿#region << 版 本 注 释 >>
/*----------------------------------------------------------------
 * 创建者：王明亮
 * 创建时间：2023/4/26 16:08:57
 * 版本：V1.0.0
 * 描述：
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时间：
 * 修改说明：
 *
 * 版本：V1.0.1
 *----------------------------------------------------------------*/
#endregion << 版 本 注 释 >>

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace chatSDKApp 
{
    /// <summary>
    /// 终端日志用
    /// </summary>
    public class LogHelper
    {
        /// <summary>
        /// 记录指定的日志
        /// </summary>
        public static void Log(string category, string log)
        {
            try
            {
                if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog")))
                    Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog"));

                string fileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
                                               "ErrLog\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
                File.AppendAllText(fileName,
                                   string.Format("[{0}][{1}] {2} {3}", DateTime.Now.ToString("H:mm:ss"), category, log,
                                                 Environment.NewLine));

            }
            catch (Exception ex)
            {

            }
        }
        /// <summary>
        /// 记录指定的日志
        /// </summary>
        public static void LogByCategory(string category, string log)
        {
            try
            {
                if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog\\Exception")))
                    Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog\\Exception"));

                string fileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
                                               "ErrLog\\Exception\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
                File.AppendAllText(fileName,
                                   string.Format("[{0}][{1}] {2} {3}", DateTime.Now.ToString("H:mm:ss"), category, log,
                                                 Environment.NewLine));

            }
            catch (Exception ex)
            {

            }
        }

        /// <summary>
        /// 记录指令目录的日志
        /// </summary>
        /// <param name="category">日志类别</param>
        /// <param name="directory">指定目录</param>
        /// <param name="log">日志内容</param>
        public static void LogByDirectory(string category, string directory, string log)
        {
            try
            {
                if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), directory)))
                    Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), directory));

                string fileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
                                               directory + "\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
                File.AppendAllText(fileName,
                                   string.Format("[{0}][{1}] {2} {3}", DateTime.Now.ToString("H:mm:ss"), category, log,
                                                 Environment.NewLine));
            }
            catch (Exception ex)
            {
            }
        }

        /// <summary>
        /// 记录指定的日志
        /// </summary>
        /// <param name="category">日志类别</param>
        /// <param name="log">要写日志的流</param>
        /// <param name="log2"></param>
        public static void Log(string category, string log, string log2)
        {
            try
            {
                if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog")))
                    Directory.CreateDirectory(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "ErrLog"));

                string fileName = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),
                                               "ErrLog\\" + DateTime.Now.ToString("yyyyMMdd") + ".txt");
                File.AppendAllText(fileName,
                                   string.Format("[{0}][{1}] {2} {3} {4} {3}", DateTime.Now.ToString("H:mm:ss"),
                                                 category, log, Environment.NewLine, log2));

            }
            catch (Exception ex)
            {
            }
        }

    }
}
